<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Services extends Controller 
{
	var $tpl;

	function setVars()
	{
		$this->tpl['head'] = '';
        //$this->tpl['sidebar'] = '<img src="/img/LogoTruck.gif" alt="PzzAzz" width="200" height="132" /><br /><br />';
        $this->tpl['sidebar'] = '<div id="Home_Truck"><img src="/img/vehicle/Home_truck.gif" alt="Truck" width="100%" /></div>';
        $this->tpl['sidebar'] .= $this->tm->randomBlock();
        //$this->tpl['sidebar'] .= '<br /><br /><br /><img src="/img/LogoTruckR.gif" alt="PzzAzz" width="200" height="132" />';
		$this->tpl['jsOnLoad']  = '';
        //$this->tpl['tpljs'][]  = '';
	}
	
	function __construct()
	{
		parent::Controller();
        $this->load->model('Tamer_Model', 'tm');
		$this->setVars();
		log_message('debug', "Services: Controler Class Initialized");
		//$this->load->library('profiler');
	}


	function index()
	{
		$this->tpl['title'] = "Services";
		$this->load->view('services/index', $this->tpl);
	}
	
	function locations()
	{
		$this->tpl['title'] = "Locations";
        $this->tpl['sidebar'] = '<h2 class="SideBar">What is the difference between a zone and a route?<ul><li>A Zone consists of a several-mile-wide area in the small radius of peoples homes, in which they travel daily.</li><li>A Route is the exact street-by-street path traveled by the PzzAzz truck from the beginning to the end of a trip.</li></ul></h2>';
		$this->load->view('services/locations', $this->tpl);	
    }
    
    /**
     * @note	Calculate Sale Price
     * @info	
     * @author	Dennis T. Kaplan
     * @access	private
     * @param	$impressions 
     * @return	Price
     */	
    private function calc($Calc)
    {
        $Calc['Impressions'] = $Calc['Impressions'] * $Calc['Type']*10000;
    	$Calc['Rate'] = 30;
        $Calc['Interval'] = 8 ; //Interval/Sec.
        $Calc['perHour'] = 3600 / $Calc['Interval'];
        $Calc['CPI'] = $Calc['Rate'] / $Calc['perHour']; //Cost Per Impression
        $Calc['HoursDay'] = 10;
        $Calc['CostOfMoney'] = 0.30; //Percent 0.25 = 25%
        $Calc['HoursPerMonth'] = $Calc['HoursDay'] * 5 * 4;
        $Calc['Months'] = $Calc['Impressions']/$Calc['perHour']/$Calc['HoursPerMonth'];
        $Calc['DiscountPerCent'] = $Calc['Months']/12*$Calc['CostOfMoney'];
        if ($Calc['DiscountPerCent'] > .5){
        	$Calc['DiscountPerCent'] = .5;
        }
        $Calc['Price'] = $Calc['Impressions']*$Calc['CPI'];
        $Calc['Sale'] = $Calc['Price'] - ($Calc['Price'] * $Calc['DiscountPerCent']);
        $Calc['Safe'] = $Calc['Price'] - $Calc['Sale'];
        
        // Printing output
        $duration = round($Calc['Impressions']/($Calc['perHour']*($Calc['HoursPerMonth']/4))*7/$Calc['Type'],2);
        $return['Approx. Duration in Weeks'] = (INT) $duration/2 . ' to ' .(INT) $duration;
        //$return['Cost Per Impression'] = '$'.round($Calc['Sale'] / $Calc['Impressions']/10,4); //Cost Per Impression
        //$return['Cost Per Mille'] = '$' .round($Calc['Sale'] / $Calc['Impressions']* 100,2);
        //$return['Discount'] = round($Calc['DiscountPerCent']*100,2).'%';
        //$return['Discount in $'] = '$'.round($Calc['Safe'],2);
        $return['Your Quote'] = '$'.number_format((int) $Calc['Sale']);
        $return['Quote including Printing'] = '$'. number_format(((int) $Calc['Sale'] + $Calc['Type'] * 300));
        return $return;
    }
    
    /**
     * @note	quote
     * @info	
     * @author	Dennis T. Kaplan
     * @access	public
     * @param	$i 
     * @return	Calculation Array
     */	
    public function quote()
    {
		$this->tpl['title'] = "Quotetion";
        $this->auth->CheckTaMeR(2);
        $submit = $this->input->post('submit');
        
        if ( $submit !== FALSE ) {
            $impressions = $Calc['Impressions'] = $this->input->post('Impressions');
            $type = $Calc['Type'] = $this->input->post('type');
            $Calc = $this->calc($Calc);
        }else{
            $impressions = $Calc['Impressions'] = 1;
            $type = $Calc['Type'] = 1;
            $Calc = $this->calc($Calc);
        }
        //printa($Calc);
    	$this->load->helper('form');
        $form[1]['Impressions'] = form_input(array(
                                        'name'        => 'Impressions',
                                        'id'          => 'Impressions',
                                        'value'       => $impressions,
                                        'maxlength'   => '4',
                                        'size'        => '2',
                                        'style'       => 'text-align: right'
                                        )
                                    ) .'0,000';
        $form[1][''] = '<strong>Genuine Value:</strong> We run between 4 and 8 billboards on each side of our Mobile Advertising Trucks. Unlike our competitors we do not sell you on weeks because we feel that would not be fair to you. We charge per impression <i>(The number of times a billboard is displayed)</i>. Therefore if we have more billboards per side your ad will run longer verses if we display less billboards per side.';
                                    

        $options = array(
                  '1'  => 'Single Billboard',
                  '3'  => 'Billboard Wrap',
                  '2'  => 'Billboard Slide Show'
                );
                
        $form[2]['Type'] = form_dropdown('type', $options, $type);
        $form[2][''] = 'Check our '.anchor('services/index','Overview').' page for the explonation and some pictures.';
        
        $form[''] =          form_submit(array('class' => 'submit', 
                                        'name'        => 'submit',
                                        'value'       => 'Submit',
                                        'style'       => 'margin:10px'
                                        )
                                    );
        $this->load->library('table');
        $attributes = array('name' => 'quote');
        $this->tpl['body'] = 'Mobile Advertising Preliminary Quote';

        $this->tpl['body'] .=  form_open("services/quote", $attributes);
        $style = 'width: 100%; border: thin solid  black;';
        $this->tpl['body'] .= $this->table->form_table($form,$style);
        //$this->tpl['body'] .= $this->table->form_table($Calc);
        $this->tpl['body'] .= '</form>';

        $this->tpl['body'] .= '<br /><br /><br />';

        $this->table->clear();
        $tmpl = array ( 'table_open'  => '<table border="1" cellpadding="10" cellspacing="1" align="center" class="table" style="text-align: center;">' );
        $this->table->set_template($tmpl);
        $this->table->set_heading('Approx. Duration in Weeks', 'Your Quote', 'Quote including Printing');
        $this->tpl['body'] .= $this->table->generate($Calc);
        $this->tpl['body'] .= '<br /><br />Prices may be adjusted according to holidays, special events, etc..';
		$this->load->view('blank', $this->tpl);
    }
}
?>
